package com.xzmzhp.controller.power;

import com.xzmzhp.pojo.power.Competence;
import com.xzmzhp.service.power.CompetenceService;
import com.xzmzhp.utils.return_tool.ReturnData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author 王源(xm)
 * @Date: 2020/11/15 19:25
 * @Description: 权限信息前台交互页面
 */
@Controller
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/competence")
public class CompetenceController {
    @Autowired
    private CompetenceService competenceService;

    /**
     * 返回所有权限信息
     *
     * @return returnData
     */
    @GetMapping("/findAll")
    @ResponseBody
    public ReturnData findAll() {
        return competenceService.findAll();
    }

    /**
     * 根据权限id返回权限信息
     *
     * @param competenceId 权限id
     * @return returnData
     */
    @RequestMapping("/findById")
    @ResponseBody
    public ReturnData findById(int competenceId) {
        return competenceService.findById(competenceId);
    }

    /**
     * 根据权限id查询所有路径
     *
     * @param competenceId 权限id
     * @return returnData
     */
    @RequestMapping("/findByCompetenceId")
    @ResponseBody
    public ReturnData findByCompetenceId(int competenceId) {
        return competenceService.findByCompetenceId(competenceId);
    }

    /**
     * 根据权限名称返回权限信息
     *
     * @param competenceName 权限名称
     * @return returnData
     */
    @RequestMapping("/findByName")
    @ResponseBody
    public ReturnData findByName(String competenceName) {
        return competenceService.findByName(competenceName);
    }

    /**
     * 添加权限信息
     *
     * @param competenceName 部门名称
     * @return returnData
     */
    @RequestMapping("/addCompetence")
    @ResponseBody
    public ReturnData addPosition(String competenceName) {
        return competenceService.addCompetence(competenceName);
    }


    /**
     * 修改部门信息
     *
     * @param competence Competence对象
     * @return returnData
     */
    @RequestMapping("/updateCompetence")
    @ResponseBody
    public ReturnData updatePosition(@RequestBody Competence competence) {
        return competenceService.updateCompetence(competence);
    }

    /**
     * 删除权限信息
     *
     * @param competenceId 权限id
     * @return returnData
     */
    @RequestMapping("/deleteCompetence")
    @ResponseBody
    public ReturnData deleteCompetence(int competenceId) {
        return competenceService.deleteCompetence(competenceId);
    }
}
